<?php

$news = new news;


if (isset($_GET['action']) && $_GET['action'] == "edit" && isset($_GET['news_id']) && is_allowed($USER_RIGHTS['news_change'])) {

	$news_id = $_GET['news_id'];

	$news_item = $news->get($news_id);

	$news_item = $news_item[0];

	$smarty->assign('news_item', $news_item);

	$smarty->display('news_edit.tpl', $_SESSION['uid']);

}elseif (isset($_GET['action']) && $_GET['action'] == "new" && is_allowed($USER_RIGHTS['news_add'])) {

	$smarty->display('news_edit.tpl', $_SESSION['uid']);

}elseif (isset($_GET['action']) && $_GET['action'] == "remove" && is_allowed($USER_RIGHTS['news_delete']))  {

	$news_id = $_GET['news_id'];

	$news->remove($news_id);

	$smarty->assign('message', "The news item has been removed!");

	$items = $news->get();

	$smarty->assign('news', $items);

	$smarty->display('news_listtpl', $_SESSION['uid']);

}elseif (isset($_POST['action']) && $_POST['action'] == "save" && is_allowed($USER_RIGHTS['news_change'])) {

	$active_character = $player->get( 0, "", 1, $_SESSION['uid']);

	$active_character = $active_character[0];

	$subject = $_POST['subject'];
	$text_body = $_POST['text_body'];
	$news_id = $_POST['news_id'];


	$news->save($news_id, $subject, $active_character['player_id'], "Now()", $text_body);

	$smarty->assign('message', "The news item has been changed/added!");

	$smarty->display('news_edit.tpl', $_SESSION['uid']);

} else {

	$items = $news->get();

	$smarty->assign('news', $items);

	$smarty->display('news_list.tpl', $_SESSION['uid']);
}





?>
